package com.jzwl.xydk.manager.importdata.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jzwl.xydk.manager.importdata.dao.ImportDataDao;
import com.jzwl.xydk.manager.importdata.pojo.ImportData;
import com.jzwl.xydk.wap.business.home.pojo.BannerInfo;

@Service("importDataService")
public class ImportDataService {
	
	@Autowired
	private ImportDataDao importDataDao;
	
	public List<ImportData> getData(){
		
		List<ImportData> list = importDataDao.getInfo();
		int i = 0;
		//对业务进行处理
		for(ImportData importData:list){
			
			//根据城市名称判断该城市下是否有没有需要的城市 如果没有数据，则进行添加
			List<ImportData> citylist=importDataDao.getCityInfo(importData.getCity());
			if(citylist.size() == 0){
				//添加城市
				boolean flag_city = importDataDao.addCity(importData.getProvice(), importData.getCity(), importData.getId());
				//存储城市成功，存储该城市下的学校
				if(flag_city){
					//从xk-city-school-info获取学校的数据
					List<ImportData> listCity =  importDataDao.getInfoByCity(importData.getCity());
					for(ImportData cityData:listCity){
						//根据学校名称判断该城市下是否含有这个学校
						List<ImportData> listSchool = importDataDao.getSchoolInfo(cityData.getSchool());
						//if(listSchool.size() == 0){//没有该学校，进行添加
							boolean temp_school = importDataDao.addSchool(cityData.getProvice(), cityData.getCity(), cityData.getId(), cityData.getSchool(), importData.getId());
							if(temp_school){
								//得到标签表
								//System.out.println("===============success====================="+cityData.getLevel());
								String  str = cityData.getLevel().replace(" ", "");
								 Map<String,Object> map =  getLabelData(str);
								 Long dicDataId = Long.parseLong(map.get("id").toString());
								//学校添加成功，维护标签表
								 boolean temp_school_label = importDataDao.addSchoolLabel(dicDataId, cityData.getId());
								 if(temp_school_label){
									 i=i+1;
									 System.out.println("===============success====================="+i+"school"+cityData.getSchool());
								 }
							}
						//}
					}
				}
			}
			
		}
		
		
		
		return list;
	}
	
	public Map<String,Object> getLabelData(String temp){
		Map<String,Object> map = importDataDao.getLabelData(temp);
		return map;
	}
	
	

}
